<template>
  <div id="my-credit">
    <div>
      <div class="credit-tabbar" @click="goBalance">
        <p>可提现余额</p>
        <p>￥{{item.avaAmt}}</p>
        <div class="rightDown" @click.stop="noBalance">不可提现金额<span>￥{{item.frezAmt | fixed}}</span></div>
        <div class="leftTop" @click.stop="myBalance">我的余额<span>￥{{item.balAmt | fixed}}</span></div>
      </div>
      <div class="circle"></div>
      <div class="all-withdraw">
          <div class="div-draw" @click="creditwithdraw"><span>提现卡</span><span>{{item.bankName + bankcard}}</span></div>
          <div class="div-draw"><span>提现金额</span><span @click="allput">全部提现</span></div>
          <group class="input-draw">
            <x-input title="￥" type="number" v-model="money" :show-clear="false"></x-input>
          </group>
      </div>
    </div>
    <div class="share" @click="apply">申请提现</div>
    <p class="check" @click="checkrecord">查看提现记录</p>
    <div class="transfer">
      <h5>提现说明</h5>
      <p>1、提现申请于每月1-10号开放，申请开放期间，可提现余额大于100元时方可申请提现； </p>
      <p>2、申请提现后，奖励将会在申请当月的21号发放至绑定的银行卡中，如遇节假日顺延； </p>
      <p>3、可提现余额：可申请提现的税后结算金额；<br /><span style="visibility:hidden">3、</span>不可提现金额：当月的税前收益；<br /><span style="visibility:hidden">3、</span>我的余额：账户总金额，我的余额=可提现余额+不可提现金额；</p>
    </div>
  </div>
</template>
<script>
var day = new Date().getDate()
var timeStamp = String(Number(new Date()))
import { XInput, Group } from 'vux'
import api from '../../api'
import utils from '../../utils'
export default {
  data () {
    return {
      item: {},
      money: '0.00',
      tokenval: '',
      bankcard: ''
    }
  },
  components: {
    XInput,
    Group
  },
  created () {
    window.document.title = '我要提现'
    this.tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
    var params = {
      Tokenuser: this.tokenval,
      userid: this.$store.state.userID,
      timestamp: timeStamp
    }
    api.person(params).then(res => {
      console.log(res)
      this.item = res.data
      var creditcode = res.data.bankCard
      if (creditcode === '') {
        this.bankcard = ''
      } else {
        this.bankcard = '(' + creditcode.substring(creditcode.length - 4) + ')'
      }
    })
    utils.jssdkwx(api, this.$wechat, this.$store)
  },
  methods: {
    noBalance () {},
    // 我的余额
    myBalance () {
      window.location.href = '/center/balancepayment'
    },
    //去可提现余额
    goBalance(){
      window.location.href = '/center/balance'
    },
    // 全部提现
    allput () {
      this.money = this.item.avaAmt
    },
    // 绑卡
    creditwithdraw () {
      window.location.href = '/setting/card'
      // if (day < 20) {
      //   this.$vux.toast.show({
      //     text: '请在20号以后修改提现卡',
      //     type: 'warn',
      //     width: '4rem'
      //   })
      // } else {
      // }
    },
    // 提现记录
    checkrecord () {
      this.$router.push('/center/record')
    },
    apply () {
      if (day > 10) {
        this.$vux.toast.show({
          text: '1-10日内方可申请',
          type: 'warn',
          width: '4rem'
        })
      } else {
        api.depositapply({
          token: this.tokenval,
          timestamp: timeStamp,
          userId: this.$store.state.userID,
          tranAmt: this.money
        }).then(res => {
          if (res.status === '200') {
            window.location.reload()
          } else {
            this.$vux.toast.show({
              text: res.message,
              type: 'warn',
              width: '4rem'
            })
          }
        })
      }
    }
  }
}
</script>
